<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0,
           maximum-scale=1.0, scaminimum-le=1.0"/>
    <title>angular实现接口回调(常见服务)</title>
    <!-- 此处讲解了服务的3中方式 -->
    <script src="js/angular.js"></script>
</head>
<body>
<!--初始化中全部是以key=value来书写的-->
    <div ng-app="myApp">
        <div ng-controller="thridController">
            {{name}}
        </div>
    </div>
</body>

<script type="text/javascript">
    var app=angular.module("myApp",[]);
    //这个是直接返回的是对象;
    app.service('providerService01', function ($http) {
        var mName='';
        this.setName= function (name) {
            mName=name;
        };

        this.getName= function () {
            return mName;
        };

        //获取接口回调数据,cache是指只能访问一次，如果访问过了
        this.getDate= function () {
           var mUrl="http://www.phonegap100.com/appapi.php?a=getPortalList&catid=20&page=1&callback=JSON_CALLBACK";
            $http.jsonp(mUrl,{cache:true}).success(function (data) {
                console.log(data);
            }).error(function () {
                alert('shishang')
            });
        }
    });

    //在此处回调接口
    app.controller("thridController",["$scope","providerService01",
        function ($scope,providerService01) {
        console.log(providerService01);
        providerService01.getDate();
    }]);
</script>
</html>